#ifndef _BUOLA_GUI_CONTAINERS_CLAYOUTCONTAINER_H_
#define _BUOLA_GUI_CONTAINERS_CLAYOUTCONTAINER_H_

#include <buola/gui/cwindow.h>

namespace buola { namespace gui {

struct CLayoutPos
{
    constexpr CLayoutPos(double pAbs=0.0,double pRel=0.0)
        :   mAbs(pAbs)
        ,   mRel(pRel)
    {}
    
    double mAbs;
    double mRel;
};

inline CLayoutPos operator+(const CLayoutPos &p1,const CLayoutPos &p2)
{
    return CLayoutPos(p1.mAbs+p2.mAbs,p1.mRel+p2.mRel);
}

inline CLayoutPos operator-(const CLayoutPos &p1,const CLayoutPos &p2)
{
    return CLayoutPos(p1.mAbs-p2.mAbs,p1.mRel-p2.mRel);
}

inline constexpr CLayoutPos operator"" _perc(long double pA)
{
    return CLayoutPos(0,pA*0.01);
}

inline constexpr CLayoutPos operator"" _perc(unsigned long long int pA)
{
    return CLayoutPos(0,pA*0.01);
}

class CLayoutContainer : public CWindow
{
    struct SLayout
    {
        PWindow mWindow;

        CLayoutPos mLeft;
        CLayoutPos mRight;
        CLayoutPos mTop;
        CLayoutPos mBottom;
    };

public:
    CLayoutContainer();
    virtual ~CLayoutContainer();

    void Add(const PWindow &pWin,const CLayoutPos &pLeft,const CLayoutPos &pTop,
                                 const CLayoutPos &pRight,const CLayoutPos &pBottom);
    
private:
    virtual void OnLayout();
    virtual void OnChildRemoved(const PWindow &pWindow);

private:
    std::vector<std::unique_ptr<SLayout>> mLayouts;
};

/*namespace gui*/ } /*namespace buola*/ }

#endif
